﻿/***************************************************************************
//* Foxit Software Inc.
//* Copyright(C) 2005-2012, all rights reserved.
//*
//* The following code is copyrighted and contains proprietary information
//* and trade secrets of Foxit Software Inc.                                                      *
***************************************************************************/
/**
* PDF Annot 基类
*/
define(function (require, exports, module) {
    require('../DataLevel.js');
    require('../Math/Point.js');
    var CPDF_Rect = require('../Math/Rect.js');

    FXREADER.PDFData.AnnotType = {
        MarkUp: 1,
        Link: 2,
        Widget: 3
    };

    FXREADER.PDFData.AnnotFlag = {
        ANNOTFLAG_INVISIBLE: 1,
        ANNOTFLAG_HIDDEN: 2,
        ANNOTFLAG_PRINT: 4,
        ANNOTFLAG_NOZOOM: 8,
        ANNOTFLAG_NOROTATE: 0x10,
        ANNOTFLAG_NOVIEW: 0x20,
        ANNOTFLAG_READONLY: 0x40,
        ANNOTFLAG_LOCKED: 0x80,
        ANNOTFLAG_TOGGLENOVIEW: 0x100
    };

    FXREADER.PDFData.BorderStyle = {
        BBS_SOLID: 0,
        BBS_DASH: 1,
        BBS_BEVELED: 2,
        BBS_INSET: 3,
        BBS_UNDERLINE: 4
    };

    FXREADER.PDFData.AnnotDataJsonFormat = {
        type: "ty",
        flag: "f",
        rect: "rc",
        content: "c",
        name: "n",
        border_width: "bw",
        border_style: "bs",
        color: "cl",

        highlight: "hl",
        QuadPoints: "Quad",
        DestInfo: "ds",

        OpenState: "op",
        ModifyDate: "md",

        State: "st",
        StateModel: "stm",

        Opcity: "ca",
        CreationDate: "cd",
        Subject: "subj",
        Title: "tit",
        Popup: "pop",
        ReplyChain: "rpy",
        StateList: "stat",

        Action: "act",
        Group: "grp",

        SubType: "subty",
        TextAnnotName: "txtn"
    };
    var AnnotDataFmt = FXREADER.PDFData.AnnotDataJsonFormat;

    FXREADER.PDFData.CPDF_Annot = function (jsonData) {
        this.m_AnnotData = jsonData; // JSON.parse(jsonData);
        this.m_ActionList = {};
        /** 用来标识Annot是否是开始编辑文档前已有的，如果是已有的Annot，在删除Annot的时候，只是设置隐藏标识
         * 这样，后台处理复杂度降低*/
        this.m_IsSourceAnnot = true; 
    };

    FXREADER.PDFData.CPDF_Annot.prototype = {
        //Annot 类型,FXREADER.PDFData.AnnotType
        GetType: function () {
            return this.m_AnnotData[AnnotDataFmt.type];
        },
        //Annot Flag标志，FXREADER.PDFData.AnnotFlag
        GetFlags: function () {
            return this.m_AnnotData[AnnotDataFmt.type];
        },

        SetFlags: function (dwFlags) {
            this.m_AnnotData[AnnotDataFmt.flag] = dwFlags;
        },

        IsVisable: function () {
            var nFlags = this.GetFlags();
            return !((nFlags & FXREADER.PDFData.AnnotFlag.ANNOTFLAG_INVISIBLE) || (nFlags & FXREADER.PDFData.AnnotFlag.ANNOTFLAG_HIDDEN) || (nFlags & FXREADER.PDFData.AnnotFlag.ANNOTFLAG_NOVIEW));
        },


        //Annot 矩形区域
        GetRect: function () {
            var rect = new CPDF_Rect(this.m_AnnotData[AnnotDataFmt.rect][0], this.m_AnnotData[AnnotDataFmt.rect][1], this.m_AnnotData[AnnotDataFmt.rect][2], this.m_AnnotData[AnnotDataFmt.rect][3]);
            return rect;
        },

        SetRect: function (rect) {
            this.m_AnnotData[AnnotDataFmt.rect][0] = rect.left;
            this.m_AnnotData[AnnotDataFmt.rect][1] = rect.top;
            this.m_AnnotData[AnnotDataFmt.rect][2] = rect.right;
            this.m_AnnotData[AnnotDataFmt.rect][3] = rect.bottom;
        },

        GetContents: function () {
            return this.m_AnnotData[AnnotDataFmt.content];
        },

        SetContents: function (szContent) {
            this.m_AnnotData[AnnotDataFmt.content] = szContent;
        },


        GetAnnotName: function () {
            return this.m_AnnotData[AnnotDataFmt.name];
        },
        SetAnnotName: function (szName) {
            this.m_AnnotData[AnnotDataFmt.name] = szName;
        },

        //border  
        SetBorderWidth: function (nWidth) {
            this.m_AnnotData[AnnotDataFmt.border_width] = nWidth;
        },
        GetBorderWidth: function () {
            return this.m_AnnotData[AnnotDataFmt.border_width];
        },

        //border style,  FXREADER.PDFData.BorderStyle
        SetBorderStyle: function (nStyle) {
            this.m_AnnotData[AnnotDataFmt.border_style] = nStyle;
        },
        GetBorderStyle: function () {
            return this.m_AnnotData[AnnotDataFmt.border_style];
        },

        SetColor: function (szColor) //#ffffff
        {
            this.m_AnnotData[AnnotDataFmt.color] = szColor;
        },
        GetColor: function () {
            return this.m_AnnotData[AnnotDataFmt.color];
        }
        ,
        GetQuadPoints: function()
        {
        	return this.m_AnnotData[AnnotDataFmt.QuadPoints];
        }
        ,
        SetQuadPoints : function(quadPoints)
        {
        	this.m_AnnotData[AnnotDataFmt.QuadPoints] = quadPoints; 
        },
        IsSourceAnnot: function()
        {
        	return this.m_IsSourceAnnot;
        },
        SetSourceAnnot: function(isSourceAnnot)
        {
        	this.m_IsSourceAnnot = isSourceAnnot;
        }
    };

    return FXREADER.PDFData.CPDF_Annot;
});